var express = require('express');
var router = express.Router();
var permission = require('../common/permission.js');

router.get('/admin/:name', permission.checkLogin, adminDownload);


function adminDownload(req, res, next) {
    var options = {
        root: './file/admin/',
        dotfiles: 'deny',
        headers: {
            'x-timestamp': Date.now(),
            'x-sent': true
        }
    };

    var fileName = decodeURI(req.params.name);
    res.sendFile(fileName, options, function(err) {
        if (err) {
            console.log(err);
            res.status(err.status).end();
        } else {
            console.log('Sent:', fileName);
        }
    });
}


module.exports = router;
